﻿using EFModel;
using IServices;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using xm.Controllers;

namespace Serives
{
    public class Teehuman_file : Ihuman_file
    {
        private readonly MyDBContext he;

        public Teehuman_file(MyDBContext he)
        {
            this.he = he;
        }
        //简历通过查询
        public Task<ResultInfo> Cdjop(int currentPage, int pageSize)
        {
            return Task.Run(() => {
                var con = he.engage_resume.Where(e => e.pass_passComment == "通过"&&e.interview_status!=10);
                var list = he.engage_resume
                    .Where(e => e.pass_passComment == "通过" && e.interview_status != 10)
                    .OrderBy(q => q.res_id).Skip((currentPage - 1) * pageSize).Take(pageSize)
                    .ToList();
                int cont = con.Count();
                ResultInfo result = new ResultInfo()
                {
                    Data = list,
                    Message = "查询数据成功",
                    Status = 200,
                    Row = cont
                };
                return result;
            });
        }
        //人力资源彻底删除
        public Task<int> Delete(human_file _File)
        {
            return Task.Run(() => {
                human_file _File1 = he.human_file.Find(_File.huf_id);
                he.Remove(_File1);
                int num = he.SaveChanges();
                return num;
            });
        }
        //人力资源删除
        public Task<int> Delt(human_file _File)
        {
            return Task.Run(() => {
                human_file _File1 = he.human_file.Find(_File.huf_id);
                _File1.human_file_status = _File.human_file_status;
                int num = he.SaveChanges();
                return num;
            });
        }
        //人力资源添加
        public Task<int> Insert(human_file _File)
        {
            return Task.Run(() =>
            {
                he.human_file.Add(_File);
                int num = he.SaveChanges();
                return num;
            });
        }
        //人力资源查询
        public Task<ResultInfo> Quer(int currentPage, int pageSize)
        {
            return Task.Run(() => {
                var con = he.human_file.Where(e=> e.check_status==0);
                var list = he.human_file
                                    .Where(e => e.check_status == 0)
                    .OrderBy(q => q.huf_id).Skip((currentPage - 1) * pageSize).Take(pageSize)
                    .ToList();
                int cont = con.Count();
                ResultInfo result = new ResultInfo()
                {
                    Data = list,
                    Message = "查询数据成功",
                    Status = 200,
                    Row = cont
                };
                return result;
            });
        }
        //人力资源通过查询
        public Task<ResultInfo> QuerF(int currentPage, int pageSize)
        {
            return Task.Run(() => {
                var con = he.human_file.Where(e => (e.human_file_status == 0 || e.human_file_status == 20));
                var list = he.human_file
                    .OrderBy(q => q.huf_id).Skip((currentPage - 1) * pageSize).Take(pageSize)
                    .Where(e => (e.human_file_status == 0 || e.human_file_status == 20))
                    .ToList();
                int cont = con.Count();
                ResultInfo result = new ResultInfo()
                {
                    Data = list,
                    Message = "查询数据成功",
                    Status = 200,
                    Row = cont
                };
                return result;
            });
        }
        //人力资删除查询
        public Task<ResultInfo> QuerG(int currentPage, int pageSize)
        {
            return Task.Run(() => {
                var con = he.human_file.Where(e => e.human_file_status == 1);
                var list = he.human_file
                                    .Where(e => e.human_file_status == 1)
                    .OrderBy(q => q.huf_id).Skip((currentPage - 1) * pageSize).Take(pageSize)
                    .ToList();
                int cont = con.Count();
                ResultInfo result = new ResultInfo()
                {
                    Data = list,
                    Message = "查询数据成功",
                    Status = 200,
                    Row = cont
                };
                return result;
            });
        }
        //人力资源通过模糊查询
        public Task<ResultInfo> QuerG0(human_file _File, int currentPage, int pageSize)
        {
            return Task.Run(() => {
                var con = he.human_file.Where(e =>  (e.human_file_status == 0 || e.human_file_status == 20)
                && e.first_kind_name == _File.first_kind_name
                && e.second_kind_name == _File.second_kind_name
                && e.third_kind_name == _File.third_kind_name
                && e.human_major_kind_name == _File.human_major_kind_name
                && e.hunma_major_name == _File.hunma_major_name
                && e.regist_time.Date >= _File.regist_time
                && e.regist_time.Date <= _File.check_time);
                var list = he.human_file
                    .OrderBy(q => q.huf_id).Skip((currentPage - 1) * pageSize).Take(pageSize)
                    .Where(e =>  (e.human_file_status == 0 || e.human_file_status == 20)
                    && e.first_kind_name == _File.first_kind_name
                    && e.second_kind_name == _File.second_kind_name
                    && e.third_kind_name == _File.third_kind_name
                    && e.human_major_kind_name == _File.human_major_kind_name
                    && e.hunma_major_name == _File.hunma_major_name
                    && e.regist_time.Date >= _File.regist_time
                    && e.regist_time.Date <= _File.check_time)
                    .ToList();
                int cont = con.Count();
                ResultInfo result = new ResultInfo()
                {
                    Data = list,
                    Message = "查询数据成功",
                    Status = 200,
                    Row = cont
                };
                return result;
            });
        }
        //人力资源删除模糊查询
        public Task<ResultInfo> QuerG1(human_file _File, int currentPage, int pageSize)
        {
            return Task.Run(() => {
                var con = he.human_file.Where(e => e.human_file_status == 1
                && e.first_kind_name == _File.first_kind_name
                && e.second_kind_name == _File.second_kind_name
                && e.third_kind_name == _File.third_kind_name
                && e.human_major_kind_name == _File.human_major_kind_name
                && e.hunma_major_name == _File.hunma_major_name
                && e.regist_time.Date >= _File.regist_time
                && e.regist_time.Date <= _File.check_time);
                var list = he.human_file
                    .OrderBy(q => q.huf_id).Skip((currentPage - 1) * pageSize).Take(pageSize)
                    .Where(e => e.human_file_status == 1
                    && e.first_kind_name == _File.first_kind_name
                    && e.second_kind_name == _File.second_kind_name
                    && e.third_kind_name == _File.third_kind_name
                    && e.human_major_kind_name == _File.human_major_kind_name
                    && e.hunma_major_name == _File.hunma_major_name
                    && e.regist_time.Date >= _File.regist_time
                    && e.regist_time.Date <= _File.check_time)
                    .ToList();
                int cont = con.Count();
                ResultInfo result = new ResultInfo()
                {
                    Data = list,
                    Message = "查询数据成功",
                    Status = 200,
                    Row = cont
                };
                return result;
            });
        }
        //人力资源模糊查询
        public Task<ResultInfo> QuerH(human_file _File, int currentPage, int pageSize)
        {
            return Task.Run(() => {
                var con = he.human_file.Where(e => e.check_status == 1
                && (e.human_file_status == 0 || e.human_file_status == 20)
                && e.first_kind_name==_File.first_kind_name
                &&e.second_kind_name==_File.second_kind_name
                &&e.third_kind_name==_File.third_kind_name
                &&e.human_major_kind_name==_File.human_major_kind_name
                &&e.hunma_major_name==_File.hunma_major_name
                && e.regist_time.Date >= _File.regist_time
                && e.regist_time.Date <= _File.check_time);
                var list = he.human_file
                    .OrderBy(q => q.huf_id).Skip((currentPage - 1) * pageSize).Take(pageSize)
                    .Where(e => e.check_status == 1
                    && (e.human_file_status == 0 || e.human_file_status == 20)
                    && e.first_kind_name == _File.first_kind_name
                    && e.second_kind_name == _File.second_kind_name
                    && e.third_kind_name == _File.third_kind_name
                    && e.human_major_kind_name == _File.human_major_kind_name
                    && e.hunma_major_name == _File.hunma_major_name
                    && e.regist_time.Date >= _File.regist_time
                    && e.regist_time.Date <= _File.check_time)
                    .ToList();
                int cont = con.Count();
                ResultInfo result = new ResultInfo()
                {
                    Data = list,
                    Message = "查询数据成功",
                    Status = 200,
                    Row = cont
                };
                return result;
            });
        }
        //人力资源未复核模糊查询
        public Task<ResultInfo> QuerH1(human_file _File, int currentPage, int pageSize)
        {
            return Task.Run(() => {
                var con = he.human_file.Where(e => e.check_status == 0
                && (e.human_file_status == 0 || e.human_file_status == 20)
                && e.first_kind_name == _File.first_kind_name
                && e.second_kind_name == _File.second_kind_name
                && e.third_kind_name == _File.third_kind_name
                && e.human_major_kind_name == _File.human_major_kind_name
                && e.hunma_major_name == _File.hunma_major_name
                && e.regist_time.Date >= _File.regist_time
                && e.regist_time.Date <= _File.check_time);
                var list = he.human_file
                    .OrderBy(q => q.huf_id).Skip((currentPage - 1) * pageSize).Take(pageSize)
                    .Where(e => e.check_status == 0
                    && (e.human_file_status == 0 || e.human_file_status == 20)
                    && e.first_kind_name == _File.first_kind_name
                    && e.second_kind_name == _File.second_kind_name
                    && e.third_kind_name == _File.third_kind_name
                    && e.human_major_kind_name == _File.human_major_kind_name
                    && e.hunma_major_name == _File.hunma_major_name
                    && e.regist_time.Date >= _File.regist_time
                    && e.regist_time.Date <= _File.check_time)
                    .ToList();
                int cont = con.Count();
                ResultInfo result = new ResultInfo()
                {
                    Data = list,
                    Message = "查询数据成功",
                    Status = 200,
                    Row = cont
                };
                return result;
            });
        }
        //人力资源复核通过查询
        public Task<ResultInfo> QuerT(int currentPage, int pageSize)
        {
            return Task.Run(() => {
                var con = he.human_file.Where(e => e.check_status == 1 && (e.human_file_status == 0 || e.human_file_status == 20 || e.human_file_status == 11));
                var list = he.human_file
                    .OrderBy(q => q.huf_id).Skip((currentPage - 1) * pageSize).Take(pageSize)
                    .Where(e => e.check_status == 1 && (e.human_file_status == 0 || e.human_file_status == 20 || e.human_file_status == 11))
                    .ToList();
                int cont = con.Count();
                ResultInfo result = new ResultInfo()
                {
                    Data = list,
                    Message = "查询数据成功",
                    Status = 200,
                    Row = cont
                };
                return result;
            });
        }
        //人力资源未复核通过查询
        public Task<ResultInfo> QuerT1(int currentPage, int pageSize)
        {
            return Task.Run(() => {
                var con = he.human_file.Where(e => e.check_status == 0);
                var list = he.human_file
                    .OrderBy(q => q.huf_id).Skip((currentPage - 1) * pageSize).Take(pageSize)
                    .Where(e => e.check_status == 0)
                    .ToList();
                int cont = con.Count();
                ResultInfo result = new ResultInfo()
                {
                    Data = list,
                    Message = "查询数据成功",
                    Status = 200,
                    Row = cont
                };
                return result;
            });
        }
        //人力资源查询回显
        public Task<human_file> Query(int id)
        {
            return Task.Run(() => {
                return he.human_file.Find(id);
            });
        }
        //简历查询回显
        public Task<engage_resume> QueryPl(int id)
        {
            return Task.Run(() => {
                return he.engage_resume.Find(id);
            });
        }
        //人力资源修改
        public Task<int> Update(human_file _File)
        {
            return Task.Run(() => {
                human_file _File1 = he.human_file.Find(_File.huf_id);
                _File1.human_name = _File.human_name;
                _File1.human_address = _File.human_address;
                _File1.human_postcode = _File.human_postcode;
                _File1.human_pro_designation = _File.human_pro_designation;
                _File1.human_telephone = _File.human_telephone;
                _File1.human_mobilephone = _File.human_mobilephone;
                _File1.human_bank = _File.human_bank;
                _File1.human_account = _File.human_account;
                _File1.human_qq = _File.human_qq;
                _File1.human_email = _File.human_email;
                _File1.human_hobby = _File.human_hobby;
                _File1.human_speciality = _File.human_speciality;
                _File1.human_sex = _File.human_sex;
                _File1.human_religion = _File.human_religion;
                _File1.human_party = _File.human_party;
                _File1.human_nationality = _File.human_nationality;
                _File1.human_race = _File.human_race;
                _File1.human_birthday = _File.human_birthday;
                _File1.human_birthplace = _File.human_birthplace;
                _File1.human_age = _File.human_age;
                _File1.human_educated_degree = _File.human_educated_degree;
                _File1.human_educated_years = _File.human_educated_years;
                _File1.human_educated_major = _File.human_educated_major;
                _File1.human_society_security_id = _File.human_society_security_id;
                _File1.human_id_card = _File.human_id_card;
                _File1.remark = _File.remark;
                _File1.salary_standard_id = _File.salary_standard_id;
                _File1.salary_standard_name = _File.salary_standard_name;
                _File1.human_histroy_records = _File.human_histroy_records;
                _File1.human_family_membership = _File.human_family_membership;
                _File1.human_picture = _File.human_picture;
                _File1.checker = _File.checker;
                _File1.check_time = _File.check_time;
                _File1.check_status =1;
                int num = he.SaveChanges();
                return num;
            });
        }
        //人力资源通过修改
        public Task<int> UpdateSe(human_file _File)
        {
            return Task.Run(() => {
                human_file _File1 = he.human_file.Find(_File.huf_id);
                _File1.human_name = _File.human_name;
                _File1.human_address = _File.human_address;
                _File1.human_postcode = _File.human_postcode;
                _File1.human_pro_designation = _File.human_pro_designation;
                _File1.human_telephone = _File.human_telephone;
                _File1.human_mobilephone = _File.human_mobilephone;
                _File1.human_bank = _File.human_bank;
                _File1.human_account = _File.human_account;
                _File1.human_qq = _File.human_qq;
                _File1.human_email = _File.human_email;
                _File1.human_hobby = _File.human_hobby;
                _File1.human_speciality = _File.human_speciality;
                _File1.human_sex = _File.human_sex;
                _File1.human_religion = _File.human_religion;
                _File1.human_party = _File.human_party;
                _File1.human_nationality = _File.human_nationality;
                _File1.human_race = _File.human_race;
                _File1.human_birthday = _File.human_birthday;
                _File1.human_birthplace = _File.human_birthplace;
                _File1.human_age = _File.human_age;
                _File1.human_educated_degree = _File.human_educated_degree;
                _File1.human_educated_years = _File.human_educated_years;
                _File1.human_educated_major = _File.human_educated_major;
                _File1.human_society_security_id = _File.human_society_security_id;
                _File1.human_id_card = _File.human_id_card;
                _File1.remark = _File.remark;
                _File1.salary_standard_id = _File.salary_standard_id;
                _File1.salary_standard_name = _File.salary_standard_name;
                _File1.human_histroy_records = _File.human_histroy_records;
                _File1.human_family_membership = _File.human_family_membership;
                _File1.human_picture = _File.human_picture;
                _File1.changer = _File.changer;
                _File1.change_time = _File.change_time;
                _File1.check_status = 0;
                int num = he.SaveChanges();
                return num;
            });
        }
        //简历状态修改
        public Task<int> Updatew(engage_resume _Resume)
        {
            return Task.Run(() =>
            {
                engage_resume engage_ = he.engage_resume.Find(_Resume.res_id);
                engage_.interview_status = _Resume.interview_status;
                int num = he.SaveChanges();
                return num;
            });
        }
    }
}
